package com.hyt.it.ogt.ks.api.kw;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.common.apiInfor.DataType;
import com.hyt.common.apiInfor.ParamType;
import com.hyt.common.utils.string.StringUtils;
import com.hyt.it.ogt.ks.api.kw.model.QuestionAnalysisDTO;
import com.hyt.it.ogt.ks.api.kw.model.QuestionAnalysisRequestDTO;
import com.hyt.it.ogt.ks.enums.BizStatusCode;
import com.hyt.it.ogt.ks.enums.CandidateStatusCode;
import com.hyt.it.ogt.ks.enums.log.CandidateOperatorLogType;
import com.hyt.it.ogt.ks.enums.log.LogEventType;
import com.hyt.it.ogt.ks.feign.model.PaperDataVO;
import com.hyt.it.ogt.ks.model.dto.ExamCandidateStatusDTO;
import com.hyt.it.ogt.ks.model.entity.*;
import com.hyt.it.ogt.ks.model.vo.CandidateLogOtherVo;
import com.hyt.it.ogt.ks.model.vo.log.FaceApplyVO;
import com.hyt.it.ogt.ks.service.*;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Api(tags = "34.考生相关接口", value = "考生相关接口")
@ApiSort(34)
@RestController
@RequestMapping("/api/candidate")
@Slf4j
public class CandidateApi {
    @Resource
    private IScoreService iScoreService;
    @Resource
    private ICandidateProcessService iCandidateProcessService;
    @Resource
    private ICandidatePaperService iCandidatePaperService;
    @Resource
    private ICandidateLogOtherService iCandidateLogOtherService;
    @Resource
    private ICandidateLogAnswerService iCandidateLogAnswerService;
    @Resource
    private ICandidateAnswerService iCandidateAnswerService;
    @Resource
    private IExamCandidateStatusService iExamCandidateStatusService;
    @Resource
    private IAnswerProgressService iAnswerProgressService;
    @Resource
    private IApplyCheckService iApplyCheckService;

    @ApiOperation(value = "34.1 统分（单个考生）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "mapJson", value = "小题标答和分数", dataType = DataType.STRING, paramType = ParamType.BODY, required = true)
    })
    @ApiOperationSort(1)
    @PutMapping("calcScoreByCandidate")
    public ApiResponse calcScoreByCandidate(@RequestParam String examId, @RequestParam String candidateId,
                                            @RequestParam Boolean isBackup, @RequestBody String mapJson) {
        try {
            //Map<String, String> map = JSON.parseObject(mapJson, Map.class);
            List<PaperDataVO> paperDataList = JSON.parseArray(mapJson, PaperDataVO.class);
            CandidateProcess one = iCandidateProcessService.lambdaQuery().select(CandidateProcess::getExamStatus)
                    .eq(CandidateProcess::getExamId, examId).eq(CandidateProcess::getCandidateId, candidateId)
                    .eq(CandidateProcess::getDelFlag, false).one();
            if (one != null && one.getExamStatus() >= CandidateStatusCode.COMMIT.getCode().intValue()) {
                //iScoreService.calcScoreByCandidate(examId, candidateId, isBackup, map);
               iScoreService.calcScoreByCandidate(examId, candidateId, paperDataList, isBackup);
            }
            return ApiResponse.builder().code(BizStatusCode.KS_SUCCESS_OK.getCode()).build();
        } catch (Exception e) {
            log.error("", e);
            return ApiResponse.builder().code(BizStatusCode.CALC_SCORE_ERROR.getCode()).build();
        }
    }

    @ApiOperation(value = "34.2 查询考生作答轨迹")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "eventType", value = "事件类型", dataType = DataType.STRING,
                    paramType = ParamType.BODY, required = false,defaultValue = "100")
    })
    @ApiOperationSort(2)
    @GetMapping("queryAnswerLog")
    public ApiResponse<List<CandidateLogAnswer>> queryAnswerLog(@RequestParam String examId, @RequestParam String candidateId,
                                                          @RequestParam(required = false,defaultValue = "100") Integer eventType) {
        try {
            LambdaQueryWrapper<CandidateLogAnswer> logQuery = Wrappers.lambdaQuery();
            logQuery.eq(CandidateLogAnswer::getExamId,examId).eq(CandidateLogAnswer::getCandidateId,candidateId);
            List<CandidateLogAnswer> list = iCandidateLogAnswerService.list(logQuery);
            return ApiResponse.<List<CandidateLogAnswer>>builder()
                            .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                            .data(list)
                            .build();
        } catch (Exception e) {
            log.error("", e);
            return ApiResponse.<List<CandidateLogAnswer>>builder()
                    .code(BizStatusCode.CANDIATE_ANSWER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.3 查询考生其他轨迹")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "eventType", value = "事件大类型", dataType = DataType.INT, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "logType", value = "事件小类型", dataType = DataType.INT, paramType = ParamType.QUERY, required = false),
    })
    @ApiOperationSort(3)
    @GetMapping("queryAnswerOtherLog")
    public ApiResponse<List<CandidateLogOther>> queryAnswerOtherLog(@RequestParam String examId, @RequestParam String candidateId,
                                                                    @RequestParam Integer eventType, @RequestParam(required = false) Integer logType) {
        try {
            LambdaQueryWrapper<CandidateLogOther> logQuery = Wrappers.lambdaQuery();
            logQuery.eq(CandidateLogOther::getExamId,examId).eq(CandidateLogOther::getCandidateId,candidateId);
            if(Objects.nonNull(eventType) && !Objects.equals(0,eventType)){
                logQuery.eq(CandidateLogOther::getEventType,eventType);
            }
            if(Objects.nonNull(logType)){
                logQuery.eq(CandidateLogOther::getOperateType,logType);
            }
            List<CandidateLogOther> list = iCandidateLogOtherService.list(logQuery);
            return ApiResponse.<List<CandidateLogOther>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("", e);
            return ApiResponse.<List<CandidateLogOther>>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.4 查询考生作答记录一条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "itemId", value = "试题id", dataType = DataType.STRING, paramType = ParamType.BODY, required = true)
    })
    @ApiOperationSort(4)
    @GetMapping("queryCandidateAnswer")
    public ApiResponse<CandidateAnswer> queryCandidateAnswer(@RequestParam String examId, @RequestParam String candidateId,
                                                             @RequestParam Integer itemId) {
        try {
            LambdaQueryWrapper<CandidateAnswer> logQuery = Wrappers.lambdaQuery();
            logQuery.eq(CandidateAnswer::getExamId,examId).eq(CandidateAnswer::getCandidateId,candidateId)
                    .eq(CandidateAnswer::getItemId,itemId).eq(CandidateAnswer::getDelFlag,Boolean.FALSE).last("LIMIT 1");
            logQuery.select(CandidateAnswer::getExamId,CandidateAnswer::getCandidateId,CandidateAnswer::getItemId,
                    CandidateAnswer::getPaperId,CandidateAnswer::getPaperVersion,CandidateAnswer::getTopicId,CandidateAnswer::getParentItemId,
                    CandidateAnswer::getItemType,CandidateAnswer::getAnswerTime);

            CandidateAnswer one = iCandidateAnswerService.getOne(logQuery);
            return ApiResponse.<CandidateAnswer>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(one)
                    .build();
        } catch (Exception e) {
            log.error("", e);
            return ApiResponse.<CandidateAnswer>builder()
                    .code(BizStatusCode.CANDIATE_ANSWER_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.5 查询考生作答记录多条")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(5)
    @GetMapping("queryCandidateAnswers")
    public ApiResponse<List<CandidateAnswer>> queryCandidateAnswers(@RequestParam String examId, @RequestParam String candidateId) {
        try {
            LambdaQueryWrapper<CandidateAnswer> logQuery = Wrappers.lambdaQuery();
            logQuery.eq(CandidateAnswer::getExamId,examId).eq(CandidateAnswer::getCandidateId,candidateId);
            logQuery.select(CandidateAnswer::getExamId,CandidateAnswer::getCandidateId,CandidateAnswer::getItemId,
                    CandidateAnswer::getPaperId,CandidateAnswer::getPaperVersion,CandidateAnswer::getTopicId,CandidateAnswer::getParentItemId,
                    CandidateAnswer::getItemType,CandidateAnswer::getAnswerTime);

            List<CandidateAnswer> list = iCandidateAnswerService.list(logQuery);
            return ApiResponse.<List<CandidateAnswer>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("", e);
            return ApiResponse.<List<CandidateAnswer>>builder()
                    .code(BizStatusCode.CANDIATE_ANSWER_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.6 批量考生获取轨迹")
    @ApiOperationSort(6)
    @PostMapping("queryCandidateLogOther")
    public ApiResponse<List<CandidateLogOther>> queryCandidateLogOther(@RequestBody CandidateLogOtherVo vo) {
        try {
            LambdaQueryWrapper<CandidateLogOther> logQuery = Wrappers.lambdaQuery();
            logQuery.select(CandidateLogOther::getCandidateId,CandidateLogOther::getOperateContent,CandidateLogOther::getOperateType);
            logQuery.eq(CandidateLogOther::getExamId,vo.getExamId()).eq(CandidateLogOther::getOperateType,vo.getOperateType());
            logQuery.in(CandidateLogOther::getCandidateId,vo.getCandidateId()).eq(CandidateLogOther::getEventType,vo.getEventType());

            List<CandidateLogOther> list = iCandidateLogOtherService.list(logQuery);
            return ApiResponse.<List<CandidateLogOther>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("批量考生获取轨迹失败", e);
            return ApiResponse.<List<CandidateLogOther>>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.7 获取考生的作答试卷信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(7)
    @GetMapping("queryCandidatePapers")
    public ApiResponse<List<CandidatePaper>> queryCandidatePapers(@RequestParam String examId, @RequestParam String candidateId) {
        try {
            LambdaQueryWrapper<CandidatePaper> paperQuery = Wrappers.lambdaQuery();
            paperQuery.select(CandidatePaper::getPaperId,CandidatePaper::getExamUseTime,CandidatePaper::getPaperVersion,CandidatePaper::getCandidateId,
                    CandidatePaper::getExamId,CandidatePaper::getPaperType);
            paperQuery.eq(CandidatePaper::getExamId,examId).eq(CandidatePaper::getCandidateId,candidateId);
            List<CandidatePaper> list = iCandidatePaperService.list(paperQuery);
            return ApiResponse.<List<CandidatePaper>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("获取考生的作答试卷信息", e);
            return ApiResponse.<List<CandidatePaper>>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.8 根据事件类型获取轨迹")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "operateType", value = "事件类型", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(8)
    @GetMapping("queryCandidateLogOtherByEventType")
    public ApiResponse<String> queryCandidateLogOtherByEventType(@RequestParam String examId, @RequestParam String operateType) {
        try {
            LambdaQueryWrapper<CandidateLogOther> logQuery = Wrappers.lambdaQuery();
            logQuery.select(CandidateLogOther::getCandidateId,CandidateLogOther::getOperateContent,CandidateLogOther::getOperateType);
            logQuery.eq(CandidateLogOther::getExamId,examId).eq(CandidateLogOther::getOperateType,operateType);
            List<CandidateLogOther> list = iCandidateLogOtherService.list(logQuery);
            return ApiResponse.<String>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(JSON.toJSONString(list))
                    .build();
        } catch (Exception e) {
            log.error("根据事件类型获取轨迹失败", e);
            return ApiResponse.<String>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.9 查询考生其他轨迹总数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "eventType", value = "事件大类型", dataType = DataType.INT, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "logType", value = "事件小类型", dataType = DataType.INT, paramType = ParamType.QUERY, required = false),
    })
    @ApiOperationSort(9)
    @GetMapping("getAnswerOtherLogCount")
    public ApiResponse<Integer> getAnswerOtherLogCount(@RequestParam String examId, @RequestParam String candidateId,
                                                    @RequestParam Integer eventType, @RequestParam(required = false) Integer logType) {
        try {
            LambdaQueryWrapper<CandidateLogOther> logQuery = Wrappers.lambdaQuery();
            logQuery.eq(CandidateLogOther::getExamId,examId).eq(CandidateLogOther::getCandidateId,candidateId);
            if(Objects.nonNull(eventType) && !Objects.equals(0,eventType)){
                logQuery.eq(CandidateLogOther::getEventType,eventType);
            }
            if(Objects.nonNull(logType)){
                logQuery.eq(CandidateLogOther::getOperateType,logType);
            }
            return ApiResponse.<Integer>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(iCandidateLogOtherService.count(logQuery))
                    .build();
        } catch (Exception e) {
            log.error("", e);
            return ApiResponse.<Integer>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.10 查询考生其他轨迹")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "eventType", value = "事件大类型", dataType = DataType.INT, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "logType", value = "事件小类型", dataType = DataType.INT, paramType = ParamType.QUERY, required = false),
    })
    @ApiOperationSort(10)
    @GetMapping("queryAnswerOtherLogByPage")
    public ApiResponse<List<CandidateLogOther>> queryAnswerOtherLogByPage(@RequestParam String examId, @RequestParam String candidateId,
                                                                    @RequestParam Integer eventType, @RequestParam(required = false) Integer logType,
                                                                          @RequestParam Integer offset, @RequestParam Integer limit) {
        try {
            List<CandidateLogOther> list = iCandidateLogOtherService.queryAnswerOtherLogByPage(examId, candidateId, eventType, logType, offset, limit);
            return ApiResponse.<List<CandidateLogOther>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("", e);
            return ApiResponse.<List<CandidateLogOther>>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.10 查询考生其他轨迹")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
            @ApiImplicitParam(name = "candidateId", value = "考生id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(10)
    @GetMapping("queryCandidateStatus")
    public ApiResponse<ExamCandidateStatusDTO> queryCandidateStatus(@RequestParam String examId, @RequestParam String candidateId) {
        try {
            ExamCandidateStatusDTO dto = iExamCandidateStatusService.queryByExamIdAndCandidateId(examId,candidateId);
            return ApiResponse.<ExamCandidateStatusDTO>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(dto)
                    .build();
        } catch (Exception e) {
            log.error("", e);
            return ApiResponse.<ExamCandidateStatusDTO>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.9 获取考生分数列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(9)
    @GetMapping("queryCandidateProcess")
    public ApiResponse<List<CandidateProcess>> queryCandidateProcess(@RequestParam String examId) {
        try {
            LambdaQueryWrapper<CandidateProcess> wrapper = Wrappers.lambdaQuery();
            wrapper.select(CandidateProcess::getCandidateId,CandidateProcess::getObjectiveScore,CandidateProcess::getAdmissionNumber);
            wrapper.eq(CandidateProcess::getExamId,examId);
            List<CandidateProcess> list = iCandidateProcessService.list(wrapper);
            return ApiResponse.<List<CandidateProcess>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("获取考生分数列表", e);
            return ApiResponse.<List<CandidateProcess>>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.10 根据考试ID获取考生答案")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
    })
    @ApiOperationSort(10)
    @GetMapping("findCandidateAnswersByExamId")
    public ApiResponse<List<CandidateAnswer>> findCandidateAnswersByExamId(@RequestParam String examId, @RequestParam Integer offset, @RequestParam Integer limit) {
        try {
            LambdaQueryWrapper<CandidateAnswer> wrapper = Wrappers.lambdaQuery();
            wrapper.select(CandidateAnswer::getCandidateId, CandidateAnswer::getPaperId, CandidateAnswer::getPaperVersion, CandidateAnswer::getItemId, CandidateAnswer::getObjectiveAnswer);
            wrapper.eq(CandidateAnswer::getExamId, examId).last("limit " + offset + "," + limit);
            List<CandidateAnswer> list = iCandidateAnswerService.list(wrapper);
            return ApiResponse.<List<CandidateAnswer>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("获取考生分数列表", e);
            return ApiResponse.<List<CandidateAnswer>>builder()
                    .code(BizStatusCode.CANDIDATE_ANSWER_BY_EXAM_ID_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.11 获取单题分析")
    @ApiOperationSort(11)
    @PostMapping("getQuestionAnalysis")
    public ApiResponse<List<QuestionAnalysisDTO>> getQuestionAnalysis(@RequestBody QuestionAnalysisRequestDTO questionAnalysis) {
        try {
            log.info("34.11 获取单题分析接收的参数【{}】", questionAnalysis.toString());
            return ApiResponse.<List<QuestionAnalysisDTO>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(iCandidateAnswerService.getQuestionAnalysis(questionAnalysis))
                    .build();
        } catch (Exception e) {
            log.error("获取单题分析", e);
            return ApiResponse.<List<QuestionAnalysisDTO>>builder()
                    .code(BizStatusCode.CANDIDATE_ANSWER_BY_EXAM_ID_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.12 重置答题时长")
    @ApiOperationSort(12)
    @GetMapping("resetAnswerTime")
    public ApiResponse<Boolean> resetAnswerTime(@RequestParam String examId, @RequestParam String candidateId,
                                                @RequestParam(required = false) Integer paperSort, @RequestParam String paperId,@RequestParam Boolean needFlag) {
        try {
            log.info("34.12 重置答题时长接收的参数【{}，{}，{}，{},{}】", examId, candidateId, paperSort, paperId,needFlag);
            return ApiResponse.<Boolean>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(iAnswerProgressService.clearCandidateProcess(examId, candidateId, paperSort,paperId,needFlag))
                    .build();
        } catch (Exception e) {
            log.error("重置答题时长异常", e);
            return ApiResponse.<Boolean>builder()
                    .code(BizStatusCode.RESET_ANSWER_TIME_ERROR.getCode())
                    .data(false)
                    .build();
        }
    }

    @ApiOperation(value = "34.13 查询申请通过人脸验证信息")
    @ApiOperationSort(13)
    @GetMapping("getApplymanualReviewFaceInfo")
    public Object getApplymanualReviewFaceInfo(@RequestParam String examId, @RequestParam String candidateId) {
        try {
            log.info("34.13 查询申请通过人脸验证信息接收的参数【{}, {}】", examId, candidateId);
            LambdaQueryWrapper<ApplyCheck> wrapper = Wrappers.lambdaQuery();
            wrapper.select(ApplyCheck::getOperateContent);
            wrapper.eq(ApplyCheck::getExamId, examId)
                    .eq(ApplyCheck::getCandidateId, candidateId)
                    .eq(ApplyCheck::getEventType, LogEventType.OPERATOR_LOG.getCode().intValue())
                    .eq(ApplyCheck::getOperateType, CandidateOperatorLogType.ID_FACE_SKIP_APPLY.getCode().intValue())
                    .orderByDesc(ApplyCheck::getUpdateDate).last("limit 1");

            ApplyCheck applyCheck = iApplyCheckService.getOne(wrapper);
            FaceApplyVO manualReviewFaceApply = new FaceApplyVO();
            if (applyCheck != null && StringUtils.isNotBlank(applyCheck.getOperateContent())) {
                manualReviewFaceApply = JSON.parseObject(applyCheck.getOperateContent(), FaceApplyVO.class);
            }
            return ApiResponse.builder().code(BizStatusCode.KS_SUCCESS_OK.getCode()).data(manualReviewFaceApply).build();
        } catch (Exception e) {
            log.error("查询申请通过人脸验证信息异常", e);
            return ApiResponse.<Boolean>builder()
                    .code(BizStatusCode.GET_MANUAL_REVIEW_FACE_APPLY_INFO_ERROR.getCode())
                    .build();
        }

    }

    @ApiOperation(value = "34.14 根据考试ID获取考生答案总数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true),
    })
    @ApiOperationSort(14)
    @GetMapping("getCandidateAnswersCountByExamId")
    public ApiResponse<Integer> getCandidateAnswersCountByExamId(@RequestParam String examId) {
        try {
            LambdaQueryWrapper<CandidateAnswer> wrapper = Wrappers.lambdaQuery();
            wrapper.eq(CandidateAnswer::getExamId, examId);
            return ApiResponse.<Integer>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(iCandidateAnswerService.count(wrapper))
                    .build();
        } catch (Exception e) {
            log.error("获取考生分数列表", e);
            return ApiResponse.<Integer>builder()
                    .code(BizStatusCode.CANDIDATE_ANSWER_BY_EXAM_ID_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.15 获取考生分数列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(15)
    @GetMapping("queryCandidateProcessPage")
    public ApiResponse<List<CandidateProcess>> queryCandidateProcessPage(@RequestParam String examId, @RequestParam Integer offset, @RequestParam Integer limit) {
        try {
            LambdaQueryWrapper<CandidateProcess> wrapper = Wrappers.lambdaQuery();
            wrapper.select(CandidateProcess::getCandidateId,CandidateProcess::getObjectiveScore,CandidateProcess::getAdmissionNumber);
            wrapper.eq(CandidateProcess::getExamId,examId).last("limit " + offset + "," + limit);
            List<CandidateProcess> list = iCandidateProcessService.list(wrapper);
            return ApiResponse.<List<CandidateProcess>>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(list)
                    .build();
        } catch (Exception e) {
            log.error("获取考生分数列表", e);
            return ApiResponse.<List<CandidateProcess>>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.16 获取考生分数总数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examId", value = "考试项目id", dataType = DataType.STRING, paramType = ParamType.QUERY, required = true)
    })
    @ApiOperationSort(16)
    @GetMapping("getCandidateProcessCount")
    public ApiResponse<Integer> getCandidateProcessCount(@RequestParam String examId) {
        try {
            LambdaQueryWrapper<CandidateProcess> wrapper = Wrappers.lambdaQuery();
            wrapper.eq(CandidateProcess::getExamId,examId);
            Integer total = iCandidateProcessService.count(wrapper);
            return ApiResponse.<Integer>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(total)
                    .build();
        } catch (Exception e) {
            log.error("获取考生分数总数", e);
            return ApiResponse.<Integer>builder()
                    .code(BizStatusCode.CANDIATE_OTHER_LOG_ERROR.getCode())
                    .build();
        }
    }

    @ApiOperation(value = "34.17 重置答题时长撤销交卷时")
    @ApiOperationSort(17)
    @GetMapping("resetAnswerTimeCancelPaper")
    public ApiResponse<Boolean> resetAnswerTimeCancelPaper(@RequestParam String examId, @RequestParam String candidateId,@RequestParam String candidatePaperId) {
        try {
            log.info("34.12 重置答题时长接收的参数【{}，{}，{}】", examId, candidateId, candidatePaperId);
            return ApiResponse.<Boolean>builder()
                    .code(BizStatusCode.KS_SUCCESS_OK.getCode())
                    .data(iAnswerProgressService.resetAnswerTimeCancelPaper(examId, candidateId, candidatePaperId))
                    .build();
        } catch (Exception e) {
            log.error("重置答题时长撤销交卷时异常", e);
            return ApiResponse.<Boolean>builder()
                    .code(BizStatusCode.RESET_ANSWER_TIME_ERROR.getCode())
                    .data(false)
                    .build();
        }
    }

}
